import shodan
from termcolor import colored

print(colored('''
''', 'yellow')) 

print(colored('Need Shodan api key with privileges (possibility to interact with shodan API.)', 'blue'))

SHODAN_API_KEY=input(colored('[set API key]=>', 'green'))

print(colored('You can choose any port for your purposes (this exploit requires port 16992.)', 'blue'))

port=input(colored('[Set port]=>', 'green'))

api = shodan.Shodan(SHODAN_API_KEY)

search = ('port:' + port)

file = open("IP.txt", "w")

api = shodan.Shodan(SHODAN_API_KEY)

def find_ip():
	try:
		results = api.search('''{s}'''.format(s=search))
		print('Results found: %s' % results['total'])
		for result in results['matches']:
				file.write('{}'.format(result['ip_str']) + '\n')
	except (shodan.APIError)as e:
		print('Error: {}'.format(e))

start=input(colored('Start search IP [press Z] =>', 'green'))

if (start=='Z','z'):
    find_ip()
